﻿

using IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class Basedal<T>:IBasedal<T> where T : class
    {
        public Basedal(myDbContext db)
        {
            Db = db;
        }

        public myDbContext Db { get; }

        public async Task<int> add(T entity)
        {
            Db.Set<T>().AddAsync(entity);
            return await Db.SaveChangesAsync();
        }

        public async Task<int> adds(List<T> entity)
        {
            Db.Set<T>().AddRangeAsync(entity);
            return await Db.SaveChangesAsync();
        }



        public async Task<int> dele(T entity)
        {
            Db.Set<T>().Remove(entity);
            return await Db.SaveChangesAsync();
        }

        public async Task<int> deles(List<T> entity)
        {
            Db.Set<T>().RemoveRange(entity);
            return await Db.SaveChangesAsync();
        }



        public async Task<int> update(T entity)
        {
            Db.Set<T>().Update(entity);
            return await Db.SaveChangesAsync();
        }

        public async Task<int> updates(List<T> entity)
        {
            Db.Set<T>().UpdateRange(entity);
            return await Db.SaveChangesAsync();
        }



        public IQueryable<T> xs()
        {
            return Db.Set<T>();
        }
    }
}
